package com.ww.springboot.boot.baseTest.design.代理;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2023-02-04 16:16
 */
public class DynamicProxy implements InvocationHandler {
    private Object target;

    public Object proxy(Object target){
        this.target = target;
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //此处代理所有方法
        System.out.println("---进入代理---" + method.getName());
        return method.invoke(target, args);
    }
}
